package com.lin.filegraph.utils.filedg;

import java.util.Map;
import java.util.Set;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 10:06
 */

public class FileGraphEdge {
    private FileGraphNode preFile;//依赖文件结点
    private FileGraphNode postFile;//被依赖文件结点
    CouplingInfo couplingInfo;//依赖信息
    private boolean isFromCompile;

    public FileGraphEdge(FileGraphNode preFile, FileGraphNode postFile, CouplingInfo couplingInfo) {
        super();
        this.preFile = preFile;
        this.postFile = postFile;
        // this.numOfDependentPreElements = numOfDependentPreElements;
        // this.numOfPreElements = numOfPreElements;
        this.couplingInfo = couplingInfo;
        // this.setCouplingTypes(couplingTypes);
    }
    public FileGraphEdge(FileGraphNode preFile, FileGraphNode postFile, CouplingInfo couplingInfo,
                         boolean isFromCompile) {
        super();
        this.preFile = preFile;
        this.postFile = postFile;
        // this.numOfDependentPreElements = numOfDependentPreElements;
        // this.numOfPreElements = numOfPreElements;
        this.couplingInfo = couplingInfo;
        this.setFromCompile(isFromCompile);
        // this.setCouplingTypes(couplingTypes);
    }

    public FileGraphEdge(FileGraphNode preFile, FileGraphNode postFile) {
        super();
        this.postFile = postFile;
        this.preFile = preFile;
    }

    public FileGraphEdge(FileGraphNode preFile, FileGraphNode postFile, boolean isFromCompile) {
        super();
        this.preFile = preFile;
        this.postFile = postFile;
        // this.numOfDependentPreElements = 1;
        // this.numOfPreElements = 1;
        this.couplingInfo = new CouplingInfo();
        this.isFromCompile = isFromCompile;
    }

    // ENDING
    public FileGraphNode getPreFile() {
        return preFile;
    }

    public FileGraphNode getPostFile() {
        return postFile;
    }

    public int getNumOfPreElements() {
        return couplingInfo.getNumerOfElements();
    }

    public int getNumOfDependElements() {
        return couplingInfo.getNumberOfCouplingElements();
    }

    public void setPreFile(FileGraphNode preFile) {
        this.preFile = preFile;
    }

    public void setPostFile(FileGraphNode postFile) {
        this.postFile = postFile;
    }

    public boolean isSameEdge(FileGraphEdge edge2) {
        if (this.getPreFile().equals(edge2.getPreFile()) && this.getPostFile().equals(edge2.getPostFile())) {
            return true;
        }
        return false;
    }

    public String getCoupleDetail() {
        String str = "[ ";
        for (CouplingType ct : getMapOfCouplingCounter().keySet()) {
            str = str + ct + ":" + getMapOfCouplingCounter().get(ct) + " ";
        }
        str += "]";
        return str;
    }

    //   @Override
//    public String toString() {
//        return "[FileEdge] " + preFile + "  -->  " + postFile + " " + couplingInfo.getCouplingTypes();
//    }

    /**
     * @return the isFromCompile
     */
    public boolean isFromCompile() {
        return isFromCompile;
    }

    /**
     * @param isFromCompile
     *            the isFromCompile to set
     */
    public void setFromCompile(boolean isFromCompile) {
        this.isFromCompile = isFromCompile;
    }

    /**
     * @return the couplingTypes
     */
    public Set<CouplingType> getCouplingTypes() {
        return couplingInfo.getCouplingTypes();
    }

    public Map<CouplingType, Integer> getMapOfCouplingCounter() {
        return couplingInfo.getMapOfCouplingCounter();
    }

    public void addCouplingType(CouplingType couplingType) {
        couplingInfo.addCouplingCount(couplingType);
    }


    /**
     * @return
     */
    public boolean isHasInheritanceDependency() {
        // TODO Auto-generated method stub
        return getCouplingTypes().contains(CouplingType.Inheritance);
    }

    public CouplingInfo getCouplingInfo() {
        return this.couplingInfo;
    }

}
